import { ISchema } from '@formily/react'

export const createFieldSchema = (component: ISchema): ISchema => {
  return {
    type: 'object',
    properties: {
      'field-group': {
        type: 'void',
        'x-component': 'CollapseItem',
        'x-component-props': {
          title: 'Field',
        },
        properties: {
          name: {
            type: 'string',
            'x-decorator': 'FormItem',
            'x-component': 'Input',
            'x-component-props': {
              placeholder: 'Field name',
            },
          },
          title: {
            type: 'string',
            'x-decorator': 'FormItem',
            'x-component': 'Input',
            'x-component-props': {
              placeholder: 'Title',
            },
          },
          description: {
            type: 'string',
            'x-decorator': 'FormItem',
            'x-component': 'Input.TextArea',
            'x-component-props': {
              placeholder: 'Description',
            },
          },
          'x-display': {
            type: 'string',
            enum: ['visible', 'hidden', 'none', ''],
            'x-decorator': 'FormItem',
            'x-component': 'Select',
            'x-component-props': {
              defaultValue: 'visible',
            },
          },
          'x-pattern': {
            type: 'string',
            enum: ['editable', 'disabled', 'readOnly', 'readPretty', ''],
            'x-decorator': 'FormItem',
            'x-component': 'Select',
            'x-component-props': {
              defaultValue: 'editable',
            },
          },
          default: {
            'x-decorator': 'FormItem',
            'x-component': 'ValueInput',
            'x-component-props': {
              placeholder: 'Default value',
            },
          },
          enum: {
            'x-decorator': 'FormItem',
            'x-component': 'DataSourceSetter',
          },
        },
      },
      'component-group': {
        type: 'void',
        'x-component': 'CollapseItem',
        'x-component-props': {
          title: 'Component',
        },
        properties: component?.properties || {},
      },
      'decorator-group': {
        type: 'void',
        'x-component': 'CollapseItem',
        'x-component-props': {
          title: 'Decorator',
        },
        properties: {
          'x-decorator-props': {
            type: 'object',
            'x-component': 'DrawerSetter',
            properties: {
              extra: {
                type: 'string',
                'x-decorator': 'FormItem',
                'x-component': 'Input',
              },
              tooltip: {
                type: 'string',
                'x-decorator': 'FormItem',
                'x-component': 'Input',
              },
            },
          },
        },
      },
      'validation-group': {
        type: 'void',
        'x-component': 'CollapseItem',
        'x-component-props': {
          title: 'Validation',
        },
        properties: {
          'x-validator': {
            type: 'array',
            'x-component': 'ValidatorSetter',
          },
          required: {
            type: 'boolean',
            'x-decorator': 'FormItem',
            'x-component': 'Switch',
          },
        },
      },
    },
  }
}